#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>
#include <stack>

using namespace std;

class CQueue {
private:
    stack<int> s1,s2;
public:
    CQueue() {
    }
    void appendTail(int value) {
        s2.push(value);
    }
    int deleteHead() {
        int ans=-1;
        if(s1.empty()){
            while(!s2.empty()){
                s1.push(s2.top());
                s2.pop();
            }
        }
        if(!s1.empty()){
            ans=s1.top();
            s1.pop();
        }
        return ans;
    }
};


int main(){
    CQueue q;
    q.appendTail(1);
    q.appendTail(2);
    cout << q.deleteHead() <<endl;
    q.appendTail(3);
    q.appendTail(4);
    cout << q.deleteHead()<<endl;
    cout << q.deleteHead()<<endl;
    cout << q.deleteHead()<<endl;


    return 0;
}